<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">确 定</el-button> -->
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)" :disabled="isOpen">确 定</multiuse-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getList } from '@/api/omSale/vehicleParameters/wholesaleProducts';
export default {
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        status:10031001,
        isEffective:10041001
      },
      selectedList: [],
      fetchApi: getList,
      isOpen: true
    };
  },
  mixins: [dictionary],
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '产品组代码',
          fieldName: 'groupCode',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '产品组名称',
          fieldName: 'groupName',
          placeholder: '请选择'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '产品组代码',
          dataIndex: 'groupCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品组名称',
          dataIndex: 'groupName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '启用标记',
          dataIndex: 'status',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1003'),
          render: p => {
            return <span>{this.createDictText(p.row.status, '1003')}</span>;
          }
        },
        {
          title: '生效日期',
          dataIndex: 'startDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '失效日期',
          dataIndex: 'endDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建日期',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    changeHandle(val) {
      this.isOpen = true;
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        let arr = this.selectedList;
        this.$emit('addchange', arr);
      }
    },
    selectChangeHandle(val) {
      if (val.length > 0) {
        this.isOpen = false;
        this.selectedList = val;
      } else {
        this.isOpen = true;
        this.selectedList = [];
      }
    }
  }
};
</script>
